#include "Server.h"
#include "./ui_Server.h"
#include <QMessageBox>
#include <QString>
#include <QByteArray>

#include "server/download_file.h"
#include "server/upload_file.h"
#include "server/server_define.h"

Server::Server(QWidget *parent) : QWidget(parent), ui(new Ui::Server) {
    ui->setupUi(this);

    download_file * reveiver = new download_file;
    QThread *thread = new QThread;
    reveiver->moveToThread(thread);// 将任务对象移到子线程中
    connect(this, &Server::listen_download_port, reveiver, &download_file::startListen);
    thread->start(); // 启动线程

    emit listen_download_port(FILE_SERVER_PORT);

    QThread::msleep(500);

    upload_file * uploader = new upload_file;
    QThread *thread2 = new QThread;
    uploader->moveToThread(thread2);// 将任务对象移到子线程中
    connect(this, &Server::listen_upload_port, uploader, &upload_file::startListen);
    thread2->start(); // 启动线程

    emit listen_upload_port(FILE_SERVER_DOWNLOAD_PORT);
}

Server::~Server() {
    delete ui;
}
